﻿using FHJFPro.Domain;
using FHJFPro.EntityFrameworkCore;
using FHJFPro.UserInfos.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.EntityFrameworkCore;
using System.Linq;
using System.Linq.Dynamic.Core;

namespace FHJFPro.Repositories.UserInfoRepository
{
    public    class UserInfoRepository : BaseRepository<UserInfo>, IUserInfoRepository
    {
        public UserInfoRepository(IDbContextProvider<FHJFProDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }

        public async Task<UserInfo> FindByNameAsync(string name)
        {
            var dbSet = await GetDbSetAsync();
            return await dbSet.FirstOrDefaultAsync(user => user.UserName == name);
        }

        public async Task<List<UserInfo>> GetListAsync(int skipCount,int maxResultCount, string sorting,string filter = null)
        {
            return await DbSet
                .WhereIf(
                    !filter.IsNullOrWhiteSpace(),
                    author => author.UserName.Contains(filter)
                )
                .OrderBy(sorting)
                .Skip(skipCount)
                .Take(maxResultCount)
                .ToListAsync();
        }
    }
}
